package com.seminario.spring.dao.user;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.seminario.spring.dao.DAOImpl;
import com.seminario.spring.domain.Perfil;
@Repository
public class PerfilDAOImpl extends DAOImpl<Perfil> implements PerfilDAO {


	@Override
	protected Class<Perfil> getEntityClass() {
		return Perfil.class;
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Perfil> getAll() {
		String query = "Selec p From Perfil";
		List<Perfil> perfiles =(List<Perfil>) entityManager.createQuery(query).getResultList();
		return perfiles;
	}

	@Override
	public Perfil getPerfil(Integer userId) {
		String query = "Select p From Perfil p where p.user.id = :userId";
		Object result = entityManager.createQuery(query).setParameter("userId", userId).getSingleResult();
		if(result != null){
			if(result instanceof Perfil){
				return (Perfil) result;
			}
		}
		return null;
	}

}
